//
//  ShowAlertView.m
//  TengyunStation
//
//  Created by Johnny on 15/11/13.
//  Copyright © 2015年 xingrong. All rights reserved.
//

#import "ShowAlertView.h"
#import "DaishouExpress.h"
#import "TSHeader.h"
#import "ReceiverDBModel.h"
#import "SocketRequest.h"
#import "Singleton.h"
#import "ComMethod.h"

#define AlertWidth          272.0
#define AlertHeight         228.0

#define LineWidth           248.0
#define ControlWidth        214.0

#define TableCellHeight     38.0
#define ShowTableCellNumber (iPhone5Later ? 3 : 2)

@interface ShowAlertView ()<SocketRequestDelegate> {
    SocketRequest *_socketRequest;
}

@end

@implementation ShowAlertView

- (id)initWithDaishouExpress:(DaishouExpress *)express {
    CGSize size = [UIScreen mainScreen].bounds.size;
        self = [super initWithFrame:CGRectMake((size.width - AlertWidth)/2.0, (size.height - AlertHeight)/2.0, AlertWidth, AlertHeight)];
    if (self) {
        self.layer.cornerRadius = 4;
        self.clipsToBounds = YES;
        self.backgroundColor = UIColorFromRGB(0xfbfbfb);
        _express = express;
        [self loadTopView];
        [self loadTableView];
        [self loadBottomView];
        _socketRequest = [[SocketRequest alloc] initWithSocketRequestDelegate:self];
        NSRange range = [express.address rangeOfString:@"#"];
        if (range.location != NSNotFound) {
            NSArray *array = [express.address componentsSeparatedByString:@"#"];
            _oldFloor = [SocketMethod subArray:array Index:0];
            _oldRoom = [SocketMethod subArray:array Index:1];
        } else {
            _oldFloor = @"";
            _oldRoom = express.address;
        }
        _floorTextField.text = _oldFloor;
        _roomTextField.text = _oldRoom;
    }
    return self;
}

- (void)loadTopView {
    _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 132)];
    _topView.backgroundColor = [UIColor clearColor];
    [self addSubview:_topView];
    _positionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 12, AlertWidth, 20)];
    _positionLabel.font = [UIFont systemFontOfSize:18];
    _positionLabel.textColor = OrangeColor;
    _positionLabel.textAlignment = NSTextAlignmentCenter;
    _positionLabel.text = [NSString stringWithFormat:@"编号：%@",_express.position];
    [_topView addSubview:_positionLabel];
    
    UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake((_topView.frame.size.width - AlertWidth)/2.0, 43.5, AlertWidth, 15)];
    lineImageView.image = [UIImage imageNamed:@"kuaid_tanc_line"];
    [_topView addSubview:lineImageView];
    UIImageView *expressImage = [[UIImageView alloc] initWithFrame:CGRectMake(12, 56, 20, 20)];
    expressImage.image = [UIImage imageNamed:@"kuaid_icon_erw"];
    [_topView addSubview:expressImage];
    _expressIdTextField = [[UITextField alloc] initWithFrame:CGRectMake(expressImage.frame.origin.x + expressImage.frame.size.width + 12, 44, ControlWidth, 44)];
    _expressIdTextField.backgroundColor = [UIColor clearColor];
    _expressIdTextField.borderStyle = UITextBorderStyleNone;
    _expressIdTextField.placeholder = @"请输入运单号";
    _expressIdTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    _expressIdTextField.delegate = self;
    _expressIdTextField.returnKeyType = UIReturnKeyNext;
    _expressIdTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _expressIdTextField.font = [UIFont systemFontOfSize:15];
    _expressIdTextField.textColor = MainTextColor;
    _expressIdTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    _expressIdTextField.text = _express.expressId;
    [_topView addSubview:_expressIdTextField];
    UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(12, 88, LineWidth, 0.5)];
    line.backgroundColor = LineColor;
    [_topView addSubview:line];
    UIImageView *phoneImage = [[UIImageView alloc] initWithFrame:CGRectMake(12, 100, 20, 20)];
    phoneImage.image = [UIImage imageNamed:@"kuaid_icon_phone"];
    [_topView addSubview:phoneImage];
    _phoneTextField = [[UITextField alloc] initWithFrame:CGRectMake(phoneImage.frame.origin.x + phoneImage.frame.size.width + 12, 88, ControlWidth, 44)];
    _phoneTextField.backgroundColor = [UIColor clearColor];
    _phoneTextField.borderStyle = UITextBorderStyleNone;
    _phoneTextField.placeholder = @"请输入手机号";
    _phoneTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    _phoneTextField.delegate = self;
    _phoneTextField.returnKeyType = UIReturnKeyNext;
    _phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _phoneTextField.font = [UIFont systemFontOfSize:15];
    _phoneTextField.textColor = MainTextColor;
    _phoneTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    [_phoneTextField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
    _phoneTextField.text = _express.telephone;
    [_topView addSubview:_phoneTextField];
    UILabel *line1 = [[UILabel alloc] initWithFrame:CGRectMake(12, 132, LineWidth, 0.5)];
    line1.backgroundColor = LineColor;
    [_topView addSubview:line1];
}

- (void)loadTableView {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 132, AlertWidth, 0)];
    _tableView.backgroundColor = UIColorFromRGB(0xebebeb);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.layer.borderColor = LineColor.CGColor;
    _tableView.layer.borderWidth = 0.5;
    [self addSubview:_tableView];
}

- (void)loadBottomView {
    _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, _tableView.frame.origin.y + _tableView.frame.size.height, self.frame.size.width, 96)];
    _bottomView.backgroundColor = [UIColor clearColor];
    [self addSubview:_bottomView];
    
    UIImageView *floorImage = [[UIImageView alloc] initWithFrame:CGRectMake(12, 12, 20, 20)];
    floorImage.image = [UIImage imageNamed:@"kuaid_icon_louh"];
    [_bottomView addSubview:floorImage];
    _floorTextField = [[UITextField alloc] initWithFrame:CGRectMake(floorImage.frame.origin.x + floorImage.frame.size.width + 12, 0, 80, 44)];
    _floorTextField.backgroundColor = [UIColor clearColor];
    _floorTextField.borderStyle = UITextBorderStyleNone;
    _floorTextField.placeholder = @"几号楼";
    _floorTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    _floorTextField.delegate = self;
    _floorTextField.returnKeyType = UIReturnKeyNext;
    _floorTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _floorTextField.font = [UIFont systemFontOfSize:15];
    _floorTextField.textColor = MainTextColor;
    _floorTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    [_floorTextField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
    [_bottomView addSubview:_floorTextField];
    UILabel *line1 = [[UILabel alloc] initWithFrame:CGRectMake(12, 44, 118, 0.5)];
    line1.backgroundColor = LineColor;
    [_bottomView addSubview:line1];
    
    UIImageView *roomImage = [[UIImageView alloc] initWithFrame:CGRectMake(line1.frame.origin.x + line1.frame.size.width + 12, 12, 20, 20)];
    roomImage.image = [UIImage imageNamed:@"kuaid_icon_fangh"];
    [_bottomView addSubview:roomImage];
    _roomTextField = [[UITextField alloc] initWithFrame:CGRectMake(roomImage.frame.origin.x + roomImage.frame.size.width + 12, 0, 80, 44)];
    _roomTextField.backgroundColor = [UIColor clearColor];
    _roomTextField.borderStyle = UITextBorderStyleNone;
    _roomTextField.placeholder = @"几号房";
    _roomTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    _roomTextField.delegate = self;
    _roomTextField.returnKeyType = UIReturnKeyNext;
    _roomTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _roomTextField.font = [UIFont systemFontOfSize:15];
    _roomTextField.textColor = MainTextColor;
    _roomTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    [_roomTextField addTarget:self action:@selector(textFieldEditingChanged:) forControlEvents:UIControlEventEditingChanged];
    [_bottomView addSubview:_roomTextField];
    UILabel *line2 = [[UILabel alloc] initWithFrame:CGRectMake(line1.frame.origin.x + line1.frame.size.width + 12, 44, 118, 0.5)];
    line2.backgroundColor = LineColor;
    [_bottomView addSubview:line2];
    
    UILabel *line3 = [[UILabel alloc] initWithFrame:CGRectMake(0, line2.frame.origin.y + 8, AlertWidth, 0.5)];
    line3.backgroundColor = LineColor;
    [_bottomView addSubview:line3];
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(0, line2.frame.origin.y + 8, AlertWidth/2.0, 44);
    cancelBtn.backgroundColor = [UIColor clearColor];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:MainTextColor forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    cancelBtn.tag = 100;
    [cancelBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:cancelBtn];
    UILabel *line4 = [[UILabel alloc] initWithFrame:CGRectMake(line3.frame.size.width/2.0, line3.frame.origin.y, 0.5, 44)];
    line4.backgroundColor = LineColor;
    [_bottomView addSubview:line4];
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.frame = CGRectMake(AlertWidth/2.0, line2.frame.origin.y + 8, AlertWidth/2.0, 44);
    sureBtn.backgroundColor = [UIColor clearColor];
    [sureBtn setTitle:@"确认" forState:UIControlStateNormal];
    [sureBtn setTitleColor:OrangeColor forState:UIControlStateNormal];
    sureBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    sureBtn.tag = 101;
    [sureBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:sureBtn];
}

- (void)buttonAction:(UIButton *)button {
    if (button.tag == 100) {//取消
        [self removeReceiverAlertView];
    } else if (button.tag == 101) {//确认接收
        [self endEditing:YES];
        if (_phoneTextField.text.length <= 0) {
            [DSToast showText:@"请输入手机号" InView:self];
        } else if (![ComMethod judgeIsLegal:_phoneTextField.text Limit:TelephoneLimit]) {
            [DSToast showText:@"请输入正确的11位手机号" InView:self];
        } else if (![ComMethod judgeIsLegal:_expressIdTextField.text Limit:ExpressIdLimit]) {
            [DSToast showText:@"请输入正确的运单号" InView:self];
        } else if (![ComMethod judgeIsLegal:_floorTextField.text Limit:FloorLimit]) {
            [DSToast showText:@"请输入正确的楼号" InView:self];
        } else if (![ComMethod judgeIsLegal:_roomTextField.text Limit:FloorLimit]) {
            [DSToast showText:@"请输入正确的房号" InView:self];
        } else if ([_express.telephone isEqualToString:_phoneTextField.text] && [_oldFloor isEqualToString:_floorTextField.text] && [_oldRoom isEqualToString:_roomTextField.text]) {
            [self removeReceiverAlertView];
        } else {
            [self saveExpressSocket];
        }
    }
}

- (void)show {
    if (!_alertWindow) {
        _alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _alertWindow.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        _alertWindow.windowLevel = UIWindowLevelNormal;
    }
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
    [_phoneTextField becomeFirstResponder];
    [_alertWindow addSubview:self];
    [_alertWindow makeKeyAndVisible];
}

//移除alertWindow
- (void)removeReceiverAlertView {
    if ([_delegate respondsToSelector:@selector(cancelAlertView)]) {
        [_delegate cancelAlertView];
    }
    [self endEditing:YES];
    [_alertWindow resignFirstResponder];
    [_alertWindow resignKeyWindow];
    _alertWindow.alpha = 0;
    _alertWindow = nil;
}
#pragma mark Socket
- (void)saveExpressSocket {
    [ToastActivity makeActivity:@"修改运单号中..." InView:self];
    NSMutableData *mutableData = [[NSMutableData alloc] initWithData:[SocketMethod socketHeadDataMethod:@"STSA"]];
    [mutableData appendBytes:[SocketMethod checkLegal:[Singleton shareInstance].userMessage.websiteId] length:64];
    [mutableData appendBytes:[SocketMethod checkLegal:_express.inWayExpressId] length:64];
    [mutableData appendBytes:[SocketMethod checkLegal:_phoneTextField.text] length:16];
    NSString *address = @"";
    if (_floorTextField.text.length > 0) {
        address = [NSString stringWithFormat:@"%@#%@",[SocketMethod checkNull:_floorTextField.text],[SocketMethod checkNull:_roomTextField.text]];
    } else {
        address = [SocketMethod checkNull:_roomTextField.text];
    }
    [mutableData appendBytes:[SocketMethod checkLegal:address] length:64];
    [_socketRequest addSocketData:mutableData SocketTag:1];
}

#pragma mark Notification
- (void)showKeyboard:(NSNotification *)notification {
    [UIView animateWithDuration:0.25 animations:^{
        self.frame = CGRectMake(self.frame.origin.x, 30, self.frame.size.width, self.frame.size.height);
    }];
}

- (void)hideKeyboard:(NSNotification *)notification {
    [UIView animateWithDuration:0.25 animations:^{
        self.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - self.frame.size.width)/2.0, ([UIScreen mainScreen].bounds.size.height - self.frame.size.height)/2.0, self.frame.size.width, self.frame.size.height);
    }];
}

//textField方法
- (void)textFieldEditingChanged:(UITextField *)textField {
    if (textField == _phoneTextField) {
        if (textField.text.length < 11) {
            NSString *sqlString = [NSString stringWithFormat:@"WHERE telephone like '%%%@%%' AND websiteId = '%@' ORDER BY saveday DESC",textField.text,[Singleton shareInstance].userMessage.websiteId];
            _phoneList = [ReceiverDBModel findByCriteria:sqlString];
            [self reloadTableView];
        } else {
            textField.text = [textField.text substringToIndex:11];
            NSString *sqlString = [NSString stringWithFormat:@"WHERE telephone = '%@' AND websiteId = '%@'",textField.text,[Singleton shareInstance].userMessage.websiteId];
            _receiverModel = [ReceiverDBModel findFirstByCriteria:sqlString];
            if (!_receiverModel) {
                _receiverModel = [[ReceiverDBModel alloc] init];
                _receiverModel.telephone = textField.text;
            }
            _floorTextField.text = _receiverModel.floor;
            _roomTextField.text = _receiverModel.room;
            [_floorTextField becomeFirstResponder];
        }
    } else if (textField == _floorTextField) {
        if (textField.text.length > 4) {
            textField.text = [textField.text substringToIndex:4];
        }
    } else if (textField == _roomTextField) {
        if (textField.text.length > 4) {
            textField.text = [textField.text substringToIndex:4];
        }
    }
    
}

#pragma mark UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField == _phoneTextField) {
        NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:TelephoneLimit] invertedSet];
        NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
        if (![string isEqualToString:filtered]) {
            return NO;
        }
    } else if (textField == _expressIdTextField) {
        NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ExpressIdLimit] invertedSet];
        NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
        if (![string isEqualToString:filtered]) {
            return NO;
        }
    } else {
        NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:FloorLimit] invertedSet];
        NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
        if (![string isEqualToString:filtered]) {
            return NO;
        }
    }
    return YES;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField == _expressIdTextField) {
        return NO;
    } else if (textField == _phoneTextField) {
        NSString *sqlString = [NSString stringWithFormat:@"WHERE telephone like '%%%@%%' AND websiteId = '%@' ORDER BY saveday DESC",textField.text,[Singleton shareInstance].userMessage.websiteId];
        _phoneList = [ReceiverDBModel findByCriteria:sqlString];
        [self reloadTableView];
    }
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField == _phoneTextField) {
        [self removeTableView];
    } else if (textField == _floorTextField) {
        _receiverModel.floor = _floorTextField.text;
    } else if (textField == _roomTextField) {
        _receiverModel.room = _roomTextField.text;
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (textField == _expressIdTextField) {
        [_phoneTextField becomeFirstResponder];
    } else if (textField == _phoneTextField) {
        [_floorTextField becomeFirstResponder];
    } else if (textField == _floorTextField) {
        [_roomTextField becomeFirstResponder];
    } else {
        [textField resignFirstResponder];
    }
    return YES;
}

//刷新数据
- (void)reloadTableView {
    float height = 0;
    if (_phoneList.count <= ShowTableCellNumber) {
        height = _phoneList.count * TableCellHeight;
    } else {
        height = ShowTableCellNumber * TableCellHeight;
    }
    [_tableView reloadData];
    [self reloadRecieveAlertViewTableHeight:height];
}

- (void)removeTableView {
    [_tableView reloadData];
    [self reloadRecieveAlertViewTableHeight:0];
}

- (void)reloadRecieveAlertViewTableHeight:(float)height {
    [UIView animateWithDuration:0.25 animations:^{
        _tableView.frame = CGRectMake(_tableView.frame.origin.x, _tableView.frame.origin.y, _tableView.frame.size.width, height);
        _bottomView.frame = CGRectMake(_bottomView.frame.origin.x, _tableView.frame.origin.y + _tableView.frame.size.height, _bottomView.frame.size.width, _bottomView.frame.size.height);
        self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, _bottomView.frame.origin.y + _bottomView.frame.size.height);
    }];
}

#pragma mark SocketRequestDelegate
- (void)socket:(GCDAsyncSocket *)socket Code:(NSString *)code Msg:(NSString *)msg Data:(NSData *)data {
    [ToastActivity dismissInView:self];
    if ([code isEqualToString:SuccessSocket]) {
        [DSToast showText:@"修改成功" InView:self];
        _express.telephone = _phoneTextField.text;
        NSMutableString *mutableString = [[NSMutableString alloc] initWithCapacity:1];
        if (_floorTextField.text.length > 0) {
            [mutableString appendString:[NSString stringWithFormat:@"%@#",_floorTextField.text]];
        }
        [mutableString appendString:_roomTextField.text];
        _express.address = mutableString;
        if (!_receiverModel) {
            _receiverModel = [[ReceiverDBModel alloc] init];
            _receiverModel.telephone = _phoneTextField.text;
            _receiverModel.floor = _floorTextField.text;
            _receiverModel.room = _roomTextField.text;
        }
        [_receiverModel saveReceiverDBModel];
        [self performSelector:@selector(removeReceiverAlertView) withObject:nil afterDelay:1];
    } else {
        [DSToast showText:msg InView:self];
    }
}

- (void)socket:(GCDAsyncSocket *)socket Msg:(NSString *)msg {
    [ToastActivity dismissInView:self];
    [DSToast showText:msg InView:self];
}

#pragma mark UITableViewDataSource,UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _phoneList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return TableCellHeight;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIndentifier = @"ReceiveAlertCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier];
        cell.backgroundColor = [UIColor clearColor];
        UILabel *phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(44, 9, 150, 20)];
        phoneLabel.backgroundColor = [UIColor clearColor];
        phoneLabel.textColor = AssistTextColor;
        phoneLabel.font = [UIFont systemFontOfSize:14];
        phoneLabel.tag = 103;
        [cell.contentView addSubview:phoneLabel];
        UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, 37.5, AlertWidth, 0.5)];
        line.backgroundColor = LineColor;
        [cell.contentView addSubview:line];
    }
    UILabel *label = (UILabel *)[cell viewWithTag:103];
    ReceiverDBModel *model = [_phoneList objectAtIndex:indexPath.row];
    label.attributedText = [self phoneAttriString:model.telephone];
    return cell;
}

- (NSAttributedString *)phoneAttriString:(NSString *)string {
    NSRange range = [string rangeOfString:_phoneTextField.text];
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:string];
    [attriString addAttribute:NSForegroundColorAttributeName value:OrangeColor range:range];
    return attriString;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ReceiverDBModel *model = [_phoneList objectAtIndex:indexPath.row];
    _phoneTextField.text = model.telephone;
    _floorTextField.text = model.floor;
    _roomTextField.text = model.room;
    _receiverModel = model;
    [self reloadRecieveAlertViewTableHeight:0];
    [_floorTextField becomeFirstResponder];
}

- (void)dealloc {
    _phoneList = nil;
    _receiverModel = nil;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}


@end
